<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateThirdOauthTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('third_oauth', [
            'id' => false,
            'comment' => '第三方用户', 
            'engine' => 'InnoDB', 
            'primary_key' => ['id', 'openid'], 
            'collation' => 'utf8mb4_general_ci',
        ]);
        $table->addColumn(Column::integer('id')->setLimit(11)->setNull(false)->setIdentity(true))
            ->addColumn('admin_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '管理员ID'])
            ->addColumn('user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '会员ID'])
            ->addColumn('provider', 'string', ['limit'  =>  20, 'comment' => '厂商'])
            ->addColumn('platform', 'string', ['limit'  =>  20, 'comment' => '平台'])
            ->addColumn('openid', 'string', ['limit'  =>  50, 'null' => false, 'default' => '', 'comment' => '平台唯一标识'])
            ->addColumn('unionid', 'string', ['limit'  =>  50, 'null' => true, 'default' => null, 'comment' => '主体唯一标识'])
            ->addColumn('nickname', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '昵称'])
            ->addColumn('avatar', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '头像'])
            ->addColumn('login_num', 'integer', ['limit'  => 10, 'default' => 0, 'comment' => '使用登录次数'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('user_id')
            ->create();
    }


    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('third_oauth');
        $table->drop();
    }
}
